<template>
  <el-dialog
    title="自研立项列表"
    :visible.sync="isOpen"
    :destroy-on-close="true"
    width="60%"
    @close="closeDialog"
  >
    <div class="pass-list-table">
      <el-table
        border
        highlight-current-row
        size="medium"
        :height="tableList.length?500:100"
        :data="tableList"
        @current-change="handleCurrentChange"
      >
        <el-table-column
          label="申请项目名称"
          align="center"
          prop="project_name"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="申请项目类型"
          align="center"
          prop="project_type"
        />
        <el-table-column
          label="申报类别"
          align="center"
          prop="apply_type"
        />
        <el-table-column
          label="药物类别"
          align="center"
          prop="medical_type"
        />
        <el-table-column
          label="状态"
          align="center"
          prop="info_status"
        >
          <template slot-scope="scope">
            <div>
              <p v-if="scope.row.info_status == 0" class="status-common">
                草稿
              </p>
              <p v-else-if="scope.row.info_status == 1" class="status-common">
                调研中
              </p>
              <p v-else-if="scope.row.info_status == 2" class="status-common">
                评估中
              </p>
              <p v-else-if="scope.row.info_status == 3" class="status-common">
                决议审批中
              </p>
              <p v-else-if="scope.row.info_status == 4" class="status-common">
                不予立项
              </p>
              <p v-else-if="scope.row.info_status == 5" class="status-common">
                暂时搁置
              </p>
              <p v-else-if="scope.row.info_status == 6" class="status-common">
                同意立项
              </p>
              <p v-else-if="scope.row.info_status == 7" class="status-common">
                立项审批中
              </p>
              <p v-else-if="scope.row.info_status == 8" class="status-common">
                拒绝
              </p>
              <p v-else-if="scope.row.info_status == 9" class="status-common">
                通过
              </p>
              <p v-else-if="scope.row.info_status == 10" class="status-common">
                已立项审批
              </p>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="申请人"
          align="center"
          prop="creator_name"
        />
        <el-table-column
          label="申请时间"
          align="center"
          prop="created_at"
        />
      </el-table>
      <pagination
        style="display: flex; justify-content: flex-end"
        :total="total"
        :page.sync="queryParams.pager.skip"
        :limit.sync="queryParams.pager.limit"
        @pagination="getPassProjectList"
      />
    </div>
    <div
      slot="footer"
      style="display:flex;justify-content:center;align-items:center;"
      class="dialog-footer"
    >
      <el-button plain @click="create">直接创建</el-button>
      <el-button type="primary" @click="selectConfrim">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { selfProjectList } from '@/api/projectInformation'
export default {
  data() {
    return {
      isOpen: false,
      tableList: [],
      currentRow: null,
      total: 0,
      queryParams: {
        pager: {
          skip: 1,
          limit: 20
        },
        info_status: 6,
        select_type: 0,
        apply_type_id: '',
        project_type_id: '',
        select_str: '',
        start_time: '',
        end_time: ''
      }
    }
  },
  created() {
    // this.getPassProjectList();
  },
  methods: {
    getPassProjectList() {
      selfProjectList(this.queryParams).then((res) => {
        if (res.code === 200) {
          this.total = res.data.total
          this.tableList = res.data.data || []
        }
      })
    },
    setCurrent(row) {
      this.$refs.singleTable.setCurrentRow(row)
    },
    handleCurrentChange(val) {
      this.currentRow = val
    },
    closeDialog() {
      this.isOpen = false
      this.currentRow = null
    },
    // 取消按钮
    close() {
      this.isOpen = false
    },
    // 打开弹框
    open() {
      this.getPassProjectList()
      this.isOpen = true
    },
    create() {
      this.close()
      this.$router.push({
        name: 'submitApproval',
        query: {
          types: 2
        }
      })
    },
    selectConfrim() {
      if (this.currentRow == null) {
        this.$message({
          type: 'error',
          message: '请选择项目',
          duration: 1500
        })
      } else {
        this.$router.push({
          name: 'submitApproval',
          query: {
            projectId: this.currentRow.id
          }
        })
        this.close()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.pass-list-table {
  ::v-deep .el-table__body tr.current-row > td {
    background-color: #ddedff;
  }
}
</style>
